#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,gv,g[100005],d[100005],v[100005],a[100005],pp[100005],minn[100005],maxn[100005],f[100005];
//pair<int,int>p[100005];
struct op{
int a;int b;bool c;	
}p[100005];
bool cmp(op a,op b){
	if(a.a!=b.a)return a.a<b.a;
	return a.b<b.b;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		
		scanf("%d%d%d%d",&n,&m,&l,&gv);
		double gvv=gv;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&d[i],&v[i],&a[i]);
			//cout<<d[i]<<' '<<v[i]<<' '<<a[i]<<'\n';
		}
		for(int i=0;i<m;i++){
			scanf("%d",&pp[i]);
		}
		for(int i=0;i<n;i++){
			if(a[i]>0){
				//cout<<"PL0";
				if(v[i]>gv)minn[i]=d[i],maxn[i]=l;
				else if(v[i]==gv)minn[i]=d[i]+1,maxn[i]=l;
				else{
					double vv=v[i],aa=a[i];
					double s=(gvv*gvv-vv*vv)/(aa*2.0);
					minn[i]=1+ceil(s)+d[i];
					maxn[i]=l;
				}
				if(minn[i]>maxn[i])f[i]=1;
			}
			else if(a[i]==0){
				//cout<<"PL1";
				if(v[i]>gv)minn[i]=d[i],maxn[i]=l;
				else f[i]=1;
			}
			else{
				//cout<<"PL2";
				if(v[i]<=gv)f[i]=1;
				else{double vv=v[i],aa=a[i];
					double s=(gvv*gvv-vv*vv)/(aa*2.0);
					minn[i]=d[i];
					//cout<<"LL"<<(int)(d[i]+ceil(s)-1)<<endl;
					maxn[i]=min((int)(d[i]+ceil(s)-1),l);
				}
			}
			}
			for(int i=0;i<n;i++){
				p[i].a=minn[i];
				p[i].b=maxn[i];
				p[i].c=f[i];
			}
			sort(p,p+n,cmp);
			for(int i=0;i<n;i++){
				g[i]=(*(upper_bound(pp,pp+m,p[i].b)-1));
			}
			int i=0,ans=1,tmp=0;
			//cout<<"DONE\n";
			//for(int i=0;i<n;i++){
			//	printf("wek %d %d %d\n",p[i]. a,p[i].b,p[i].c);
			//}
			while(i<n){
				//cout<<"LPPO"<<i<<endl;
				if(p[i].c){i++;continue;}
				if(p[i].a>g[tmp]){
					ans++;
					tmp=i;
				}
				i++;
				//cout<<i<<"QQ";
			}//cout<<i<<"QrQ";
			int ans2=0;
			//for(int i=0;i<m;i++)
			//cout<<pp[i]<<"M"<<endl;
			for(int i=0;i<n;i++){
				if(!p[i].c&&g[i]>=p[i].a)ans2++;
				//cout<<"GG"<<g[i]<<endl;
			}
			printf("%d %d\n",ans2,n-ans);
		
	}
	return 0;
}
